package cn.acmoj.oj.service;

import cn.acmoj.oj.bean.Contest;
import cn.acmoj.oj.dao.IContestDao;
import cn.acmoj.oj.dao.ISolutionDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * cn.acmoj.oj.service
 * Springer
 * 2018-01-17
 */
@Service
public class ContestService {

    @Resource
    private IContestDao iContestDao;
    @Resource
    private ISolutionDao iSolutionDao;

    public List<Contest> getAll(String type, boolean defunct) {
        Map<String, Object> param = new HashMap<>();
        Timestamp time = new Timestamp(System.currentTimeMillis());
        if (!defunct) {
            param.put("defunct", 'N');
        }
        param.put("time", time);
        param.put("type", type);
        return iContestDao.getByParam(param);
    }

    public Contest getOnce(int id) {
        Map<String, Object> param = new HashMap<>();
        param.put("contest_id", id);
        try {
            return iContestDao.getByParam(param).get(0);
        } catch (Exception e) {
            return null;
        }
    }

}
